<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>HashMap 源码分析 | IT浮云</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="HashMap对于每一个开发者来说再熟悉不过了，本文就来讲讲它究竟是如何实现的。最开始我并不打算直接对着源码来说这些，从生活中具体事情来说原理，可以让人印象更深刻，也更容易理解！">
<meta name="keywords" content="HashMap">
<meta property="og:type" content="article">
<meta property="og:title" content="HashMap 源码分析">
<meta property="og:url" content="http://www.itfuyun.com/posts/hashmap-source-code-analysis.html">
<meta property="og:site_name" content="IT浮云">
<meta property="og:description" content="HashMap对于每一个开发者来说再熟悉不过了，本文就来讲讲它究竟是如何实现的。最开始我并不打算直接对着源码来说这些，从生活中具体事情来说原理，可以让人印象更深刻，也更容易理解！">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://blog-img.itfuyun.com/blog/post/59e1b454e4b040dc85061bcb.png">
<meta property="og:image" content="http://blog-img.itfuyun.com/blog/post/20171014160642.png">
<meta property="og:image" content="http://blog-img.itfuyun.com/blog/post/59c60d5eecf0c062c397bdc2.png?222">
<meta property="og:image" content="http://blog-img.itfuyun.com/blog/post/hashmap1.7.png">
<meta property="og:image" content="http://blog-img.itfuyun.com/blog/post/hashmap1.8.png">
<meta property="og:image" content="http://blog-img.itfuyun.com/hashmap.png">
<meta property="og:updated_time" content="2017-10-20T12:55:23.135Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="HashMap 源码分析">
<meta name="twitter:description" content="HashMap对于每一个开发者来说再熟悉不过了，本文就来讲讲它究竟是如何实现的。最开始我并不打算直接对着源码来说这些，从生活中具体事情来说原理，可以让人印象更深刻，也更容易理解！">
<meta name="twitter:image" content="http://blog-img.itfuyun.com/blog/post/59e1b454e4b040dc85061bcb.png">
    

    
        <link rel="alternate" href="/atom.xml" title="IT浮云" type="application/atom+xml" />
    

    
        <link rel="icon" href="/favicon.ico" />
    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">

    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">IT浮云</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/.">首页</a>
                
                    <a class="main-nav-link" href="/archives">文章</a>
                
                    <a class="main-nav-link" href="/about">关于</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/css/images/head.jpg" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td><a class="main-nav-link" href="/.">首页</a></td>
                
                    <td><a class="main-nav-link" href="/archives">文章</a></td>
                
                    <td><a class="main-nav-link" href="/about">关于</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/css/images/head.jpg" />
            <h2 id="name">IT浮云</h2>
            <h3 id="title">非典型程序员</h3>
            <span id="location"><i class="fa fa-map-marker"></i>深圳, 中国</span>
            <a id="follow" target="_blank" href="https://github.com/itfuyun/">关注我</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                6
                <span>文章</span>
            </div>
            <div class="article-info-block">
                7
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="http://github.com/itfuyun/" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="mailto:itfuyun@gmail.com" target="_blank" title="envelope" class=tooltip>
                            <i class="fa fa-envelope"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="weibo" class=tooltip>
                            <i class="fa fa-weibo"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/atom.xml" target="_blank" title="rss" class=tooltip>
                            <i class="fa fa-rss"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-hashmap-source-code-analysis" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            HashMap 源码分析
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/posts/hashmap-source-code-analysis.html">
            <time datetime="2017-10-14T06:31:55.000Z" itemprop="datePublished">2017-10-14</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/source-code-analysis/">源码分析</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/HashMap/">HashMap</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
                <div id="toc" class="toc-article">
                <strong class="toc-title">文章目录</strong>
                    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#生活小例子"><span class="toc-number">1.</span> <span class="toc-text">生活小例子</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#发现问题"><span class="toc-number">1.1.</span> <span class="toc-text">发现问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#解决问题"><span class="toc-number">1.2.</span> <span class="toc-text">解决问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#问题升级"><span class="toc-number">1.3.</span> <span class="toc-text">问题升级</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#最终方案"><span class="toc-number">1.4.</span> <span class="toc-text">最终方案</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HashMap-结构图"><span class="toc-number">2.</span> <span class="toc-text">HashMap 结构图</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#jdk1-7结构图"><span class="toc-number">2.1.</span> <span class="toc-text">jdk1.7结构图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#jdk1-8结构图"><span class="toc-number">2.2.</span> <span class="toc-text">jdk1.8结构图</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HashMap-源码解析"><span class="toc-number">3.</span> <span class="toc-text">HashMap 源码解析</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#关键变量"><span class="toc-number">3.1.</span> <span class="toc-text">关键变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#关键类与方法"><span class="toc-number">3.2.</span> <span class="toc-text">关键类与方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#hash-方法"><span class="toc-number">3.2.1.</span> <span class="toc-text">hash()方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Node类"><span class="toc-number">3.2.2.</span> <span class="toc-text">Node类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#put-K-key-V-value-方法"><span class="toc-number">3.2.3.</span> <span class="toc-text">put(K key, V value)方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#get-Object-key-方法"><span class="toc-number">3.2.4.</span> <span class="toc-text">get(Object key)方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
                </div>
            
            <p>HashMap对于每一个开发者来说再熟悉不过了，本文就来讲讲它究竟是如何实现的。最开始我并不打算直接对着源码来说这些，从生活中具体事情来说原理，可以让人印象更深刻，也更容易理解！<br><a id="more"></a></p>
<h2 id="生活小例子"><a href="#生活小例子" class="headerlink" title="生活小例子"></a>生活小例子</h2><h3 id="发现问题"><a href="#发现问题" class="headerlink" title="发现问题"></a>发现问题</h3><p>生活中你是一个热爱看书的人，所以私底下藏有很多书籍，像《白夜行》、《三体》等，刚开始你都是把书随意放在桌子上，每天看看书喝喝茶，日子过的非常惬意。随着时间增长，你的书也越来越多。慢慢的问题出现了，由于书都是无规则的放在桌子上，少的时候还好，这书多了以后，想快速找到需要的那本书越来越困难，可能翻个几分钟都找不到，有木有？</p>
<h3 id="解决问题"><a href="#解决问题" class="headerlink" title="解决问题"></a>解决问题</h3><p>这样下去不是办法，机智的你灵光一闪，想到一个办法。这样无规则的摆放增加了我找书的难度，为了快速找到我需要的书籍，我可以把桌子分为N个区域，每个区域用A、B、C这样的字母来标记，然后把书名第一个字的首字母按这个区域标记来规则的摆放（如：安徒生童话=》A，白夜行=》B），当我要找书的时候，可以直接根据名字就能快速的定位到书在哪个区域，找到区域后再找到想要的那本书，速度大大提升了，你心里美滋滋的，效果图如下</p>
<p><img src="http://blog-img.itfuyun.com/blog/post/59e1b454e4b040dc85061bcb.png" alt="图一"></p>
<p>书本《安徒生童话》的首字母为A，因此这本书被你放到了A标记的区域，而《白夜行》和《白鹿原》的首字母都是B，所以它们两个都应该放到B区域中，就这样你把所有的书籍都按这个规则整理好了。相比之前，现在想找一本书简直快的多了，比如我想要看《三体》，直接找到书桌上S标记的区域，然后在这区域叠起来的一摞书中找就是了！这个时候你太佩服自己了。</p>
<h3 id="问题升级"><a href="#问题升级" class="headerlink" title="问题升级"></a>问题升级</h3><p>这样的设计让你舒舒服服的过了很久，可是时间久了你又遇到一个问题了：B区域的书太多了。我找一本首字母为B开头的书还是需要费很大力气呀，这个时候你又陷入了沉思，能不能对这里稍微再改进呢？</p>
<h3 id="最终方案"><a href="#最终方案" class="headerlink" title="最终方案"></a>最终方案</h3><p>有一天，你在X宝无意中发现一个东西</p>
<p><img src="http://blog-img.itfuyun.com/blog/post/20171014160642.png" alt="图二（图片来源网络）"></p>
<p>咦，这个东西不错呀，把某个区域过多的书用这个代替，在这个书架中你可以再设定自己的一套规则（比如书名不超过5个字的可以放右侧，超过了的就放左侧），方便更快速的找书，完美！当然你不会每个区域都买个小书架，这样成本太高了，所以你决定每当某个区域的书本多于N的时候（N由你自己决定），你就放一个小书架到这个区域里面，最终方案如下</p>
<p><img src="http://blog-img.itfuyun.com/blog/post/59c60d5eecf0c062c397bdc2.png?222" alt="图三"></p>
<p>经过上面的文字，你知道HashMap的原理了吗？</p>
<h2 id="HashMap-结构图"><a href="#HashMap-结构图" class="headerlink" title="HashMap 结构图"></a>HashMap 结构图</h2><h3 id="jdk1-7结构图"><a href="#jdk1-7结构图" class="headerlink" title="jdk1.7结构图"></a>jdk1.7结构图</h3><p>如果仔细读了上面的小故事，我想HashMap的原理大概已经知道了，现在我们来看下HashMap1.7的结构图</p>
<p><img src="http://blog-img.itfuyun.com/blog/post/hashmap1.7.png" alt="图四"></p>
<p>看到这个图是不是和上文中的书桌与书本极其相识？这里的table[]数组表示书桌，数组的每一个元素代表书桌的标记字母的区域，而entry节点表示书本。HashMap不断的存取数据（put方法）其实就是不断的向书桌增加书本。在HashMap里面有个概念叫Hash冲突，就是类似不同书本的首字母可能会相同，在书桌上我们采用一本本的叠加起来解决问题，相当于上图当中的链表。</p>
<h3 id="jdk1-8结构图"><a href="#jdk1-8结构图" class="headerlink" title="jdk1.8结构图"></a>jdk1.8结构图</h3><p>在上面的故事中已经提到了，当书桌某个区域中的书越来越多的时候，我们在里面加了个小书架，因此在HashMap1.8中同样为了优化区域中搜索而引入了红黑树，来看下HashMap1.8的结构图</p>
<p><img src="http://blog-img.itfuyun.com/blog/post/hashmap1.8.png" alt="图五"></p>
<p>在HashMap1.8中引入了红黑树，能在链表长度过多的时候，增加查询速度。这就跟上面书桌区域中引入一个书架是一个道理，由于书太多，一本本的查询还是会花比较多的时间，针对区域进行优化，可以更快速的找到想要的书。</p>
<blockquote>
<p>好了，说了这么多，是时候进入主题了。</p>
</blockquote>
<h2 id="HashMap-源码解析"><a href="#HashMap-源码解析" class="headerlink" title="HashMap 源码解析"></a>HashMap 源码解析</h2><h3 id="关键变量"><a href="#关键变量" class="headerlink" title="关键变量"></a>关键变量</h3><p>在HashMap源码中有几个关键变量，我们必须知道，通过这些变量我们可以更容易理解它的底层原理，注意这里的源码是基于1.8版本的</p>
<figure class="highlight zephir"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * The default initial capacity - MUST be a power of two.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> DEFAULT_INITIAL_CAPACITY = <span class="number">1</span> &lt;&lt; <span class="number">4</span>; <span class="comment">// aka 16</span></div><div class="line"></div><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * The maximum capacity, used if a higher value is implicitly specified</span></div><div class="line"><span class="comment"> * by either of the constructors with arguments.</span></div><div class="line"><span class="comment"> * MUST be a power of two &lt;= 1&lt;&lt;30.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> MAXIMUM_CAPACITY = <span class="number">1</span> &lt;&lt; <span class="number">30</span>;</div><div class="line"></div><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * The load factor used when none specified in constructor.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">float</span> DEFAULT_LOAD_FACTOR = <span class="number">0.75</span>f;</div><div class="line"></div><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * The bin count threshold for using a tree rather than list for a</span></div><div class="line"><span class="comment"> * bin.  Bins are converted to trees when adding an element to a</span></div><div class="line"><span class="comment"> * bin with at least this many nodes. The value must be greater</span></div><div class="line"><span class="comment"> * than 2 and should be at least 8 to mesh with assumptions in</span></div><div class="line"><span class="comment"> * tree removal about conversion back to plain bins upon</span></div><div class="line"><span class="comment"> * shrinkage.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> TREEIFY_THRESHOLD = <span class="number">8</span>;</div><div class="line"></div><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * The bin count threshold for untreeifying a (split) bin during a</span></div><div class="line"><span class="comment"> * resize operation. Should be less than TREEIFY_THRESHOLD, and at</span></div><div class="line"><span class="comment"> * most 6 to mesh with shrinkage detection under removal.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> UNTREEIFY_THRESHOLD = <span class="number">6</span>;</div><div class="line"></div><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * The smallest table capacity for which bins may be treeified.</span></div><div class="line"><span class="comment"> * (Otherwise the table is resized if too many nodes in a bin.)</span></div><div class="line"><span class="comment"> * Should be at least 4 * TREEIFY_THRESHOLD to avoid conflicts</span></div><div class="line"><span class="comment"> * between resizing and treeification thresholds.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> MIN_TREEIFY_CAPACITY = <span class="number">64</span>;</div></pre></td></tr></table></figure>
<ul>
<li><p>static final int DEFAULT_INITIAL_CAPACITY = 1 &lt;&lt; 4；默认起始容量，就是table数组的默认长度（2的4次方），相当于书桌上的区域数量，必须为2的N次方（为什么？后面解释）。</p>
</li>
<li><p>static final int MAXIMUM_CAPACITY = 1 &lt;&lt; 30；最大容量，table数组的长度不能超过这个（2的30次方），即使超过也不会再改变。</p>
</li>
<li><p>static final float DEFAULT_LOAD_FACTOR = 0.75f；加载因子，这个干嘛的呢？我们知道table是一个数组，初始化的时候都必须指定一个长度，随着HashMap不断的put东西进去，这个数组需要扩容也就是增加长度。这个时候就是根据这个加载因子来扩容的，初始化的时候为16，当数组中的元素数量达到16*0.75=12的时候，table长度会变成原来的两倍。</p>
</li>
<li><p>static final int TREEIFY_THRESHOLD = 8；链表转红黑树阈值，当链表数量超过这个数的时候，它会将链表转为红黑树（这里并不打算讲红黑树的特性，具体百度，严格来说还有一个因素会影响是否转化成红黑树MIN_TREEIFY_CAPACITY，具体往下看）。</p>
</li>
<li><p>static final int UNTREEIFY_THRESHOLD = 6；红黑树转链表阈值，当红黑树数量小于这个数的时候，它会将红黑树转变为链表。</p>
</li>
<li><p>static final int MIN_TREEIFY_CAPACITY = 64；这个也是链表转为红黑树的一个条件，前面提到的一个条件是链表中的个数要大于8。而这里则是table数组的长度需要超过64，也就是说只有两个条件达到才会由链表转化为红黑树。</p>
</li>
</ul>
<h3 id="关键类与方法"><a href="#关键类与方法" class="headerlink" title="关键类与方法"></a>关键类与方法</h3><h4 id="hash-方法"><a href="#hash-方法" class="headerlink" title="hash()方法"></a>hash()方法</h4><p>hash方法对应将书本名称换算成字母的一个方法，如hash(“安徒生童话”) = A，贴上源码<br><figure class="highlight processing"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="built_in">int</span> hash(<span class="keyword">Object</span> <span class="built_in">key</span>) &#123;</div><div class="line">    <span class="built_in">int</span> h;</div><div class="line">    <span class="keyword">return</span> (<span class="built_in">key</span> == <span class="keyword">null</span>) ? <span class="number">0</span> : (h = <span class="built_in">key</span>.hashCode()) ^ (h &gt;&gt;&gt; <span class="number">16</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>该方法能将一个key转换成int型的值。需要注意的是不同的key经过hash方法得到的值有可能是相同的，这就是所谓的hash冲突，前面也提到了，解决hash冲突主要采用的是拉链式的链表结构。从代码上我们也可以知道，当key为null的时候，统一规定hash返回为0，也就是说key为null的键值对会被放在table[0]这个区域里面（类似书桌第一块区域）。</p>
<h4 id="Node类"><a href="#Node类" class="headerlink" title="Node类"></a>Node类</h4><p>Node是HashMap中的一个内部类，充当书桌上的书这一角色，组成链表的关键，先来看源码<br><figure class="highlight processing"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"><span class="comment"> * Basic hash bin node, used for most entries.  (See below for</span></div><div class="line"><span class="comment"> * TreeNode subclass, and in LinkedHashMap for its Entry subclass.)</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> class Node&lt;K,V&gt; implements Map.Entry&lt;K,V&gt; &#123;</div><div class="line">    <span class="keyword">final</span> <span class="built_in">int</span> hash;</div><div class="line">    <span class="keyword">final</span> K <span class="built_in">key</span>;</div><div class="line">    V value;</div><div class="line">    Node&lt;K,V&gt; next;</div><div class="line"></div><div class="line">    Node(<span class="built_in">int</span> hash, K <span class="built_in">key</span>, V value, Node&lt;K,V&gt; next) &#123;</div><div class="line">        <span class="keyword">this</span>.hash = hash;</div><div class="line">        <span class="keyword">this</span>.<span class="built_in">key</span> = <span class="built_in">key</span>;</div><div class="line">        <span class="keyword">this</span>.value = value;</div><div class="line">        <span class="keyword">this</span>.next = next;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">public</span> <span class="keyword">final</span> K getKey()        &#123; <span class="keyword">return</span> <span class="built_in">key</span>; &#125;</div><div class="line">    <span class="keyword">public</span> <span class="keyword">final</span> V getValue()      &#123; <span class="keyword">return</span> value; &#125;</div><div class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">String</span> toString() &#123; <span class="keyword">return</span> <span class="built_in">key</span> + <span class="string">"="</span> + value; &#125;</div><div class="line"></div><div class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="built_in">int</span> hashCode() &#123;</div><div class="line">        <span class="keyword">return</span> Objects.hashCode(<span class="built_in">key</span>) ^ Objects.hashCode(value);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">public</span> <span class="keyword">final</span> V setValue(V newValue) &#123;</div><div class="line">        V oldValue = value;</div><div class="line">        value = newValue;</div><div class="line">        <span class="keyword">return</span> oldValue;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="built_in">boolean</span> equals(<span class="keyword">Object</span> o) &#123;</div><div class="line">        <span class="keyword">if</span> (o == <span class="keyword">this</span>)</div><div class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">        <span class="keyword">if</span> (o <span class="keyword">instanceof</span> Map.Entry) &#123;</div><div class="line">            Map.Entry&lt;?,?&gt; e = (Map.Entry&lt;?,?&gt;)o;</div><div class="line">            <span class="keyword">if</span> (Objects.equals(<span class="built_in">key</span>, e.getKey()) &amp;&amp;</div><div class="line">                Objects.equals(value, e.getValue()))</div><div class="line">                <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>用通俗的话来说明上面的具体参数，hash指书名经过规则换算成A字母，key值书本名称，value指具体的书，next盖在当前书上书籍，形成拉链式的结构。</p>
<h4 id="put-K-key-V-value-方法"><a href="#put-K-key-V-value-方法" class="headerlink" title="put(K key, V value)方法"></a>put(K key, V value)方法</h4><p>看了源码的话我们会发现，在HashMap中的put方法实际上是调用了另外一个方法putVal。<br><figure class="highlight cs"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> V <span class="title">put</span>(<span class="params">K key, V <span class="keyword">value</span></span>) </span>&#123;</div><div class="line">    <span class="keyword">return</span> putVal(hash(key), key, <span class="keyword">value</span>, <span class="literal">false</span>, <span class="literal">true</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>因此我们接下来看putVal这个方法，每行都补充了相关注释<br><figure class="highlight processing"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">final</span> V putVal(<span class="built_in">int</span> hash, K <span class="built_in">key</span>, V value, <span class="built_in">boolean</span> onlyIfAbsent,</div><div class="line">               <span class="built_in">boolean</span> evict) &#123;</div><div class="line">    Node&lt;K,V&gt;[] tab; Node&lt;K,V&gt; p; <span class="built_in">int</span> n, i;</div><div class="line">    <span class="comment">//将table赋值给tab，如果table为空或者长度为0，则调用resize()初始化，再把长度赋值给n</span></div><div class="line">    <span class="keyword">if</span> ((tab = table) == <span class="keyword">null</span> || (n = tab.length) == <span class="number">0</span>)</div><div class="line">        n = (tab = resize()).length;</div><div class="line">    <span class="comment">//这里(n - 1) &amp; hash相当于hash%(n-1)，判断tab[i]这个区域是否已经有值，如果没有，则新建一个节点，并且赋值给p，把节点放到这个区域</span></div><div class="line">    <span class="keyword">if</span> ((p = tab[i = (n - <span class="number">1</span>) &amp; hash]) == <span class="keyword">null</span>)</div><div class="line">        tab[i] = newNode(hash, <span class="built_in">key</span>, value, <span class="keyword">null</span>);</div><div class="line">    <span class="comment">//如果tab[i]里面已经存在值了</span></div><div class="line">    <span class="keyword">else</span> &#123;</div><div class="line">        Node&lt;K,V&gt; e; K k;</div><div class="line">        <span class="comment">//如果p这个节点的传进来的是一样的，则把p赋值给e</span></div><div class="line">        <span class="keyword">if</span> (p.hash == hash &amp;&amp;</div><div class="line">            ((k = p.<span class="built_in">key</span>) == <span class="built_in">key</span> || (<span class="built_in">key</span> != <span class="keyword">null</span> &amp;&amp; <span class="built_in">key</span>.equals(k))))</div><div class="line">            e = p;</div><div class="line">        <span class="comment">//如果p为树类型节点，则调用树的putTreeVal方法，此方法就是一个红黑树添加</span></div><div class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (p <span class="keyword">instanceof</span> TreeNode)</div><div class="line">            e = ((TreeNode&lt;K,V&gt;)p).putTreeVal(<span class="keyword">this</span>, tab, hash, <span class="built_in">key</span>, value);</div><div class="line">        <span class="comment">//遍历区域中所有节点</span></div><div class="line">        <span class="keyword">else</span> &#123;</div><div class="line">            <span class="keyword">for</span> (<span class="built_in">int</span> binCount = <span class="number">0</span>; ; ++binCount) &#123;</div><div class="line">                <span class="comment">//将p的子节点赋值给e，如果区域中没有相同key的节点则直接插入到区域中（可能是链表可能是红黑树，具体查看treeifyBin方法），退出循环</span></div><div class="line">                <span class="keyword">if</span> ((e = p.next) == <span class="keyword">null</span>) &#123;</div><div class="line">                    p.next = newNode(hash, <span class="built_in">key</span>, value, <span class="keyword">null</span>);</div><div class="line">                    <span class="keyword">if</span> (binCount &gt;= TREEIFY_THRESHOLD - <span class="number">1</span>) <span class="comment">// -1 for 1st</span></div><div class="line">                        treeifyBin(tab, hash);</div><div class="line">                    <span class="keyword">break</span>;</div><div class="line">                &#125;</div><div class="line">                <span class="comment">//如果区域中有相同key的节点直接退出循环，</span></div><div class="line">                <span class="keyword">if</span> (e.hash == hash &amp;&amp;</div><div class="line">                    ((k = e.<span class="built_in">key</span>) == <span class="built_in">key</span> || (<span class="built_in">key</span> != <span class="keyword">null</span> &amp;&amp; <span class="built_in">key</span>.equals(k))))</div><div class="line">                    <span class="keyword">break</span>;</div><div class="line">                <span class="comment">//以上都没有，则e赋值给p继续循环</span></div><div class="line">                p = e;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="comment">//e不为空，说明之前区域中存在key与现在新的key相同，这时候将新值覆盖原来的旧值，并且返回旧值</span></div><div class="line">        <span class="keyword">if</span> (e != <span class="keyword">null</span>) &#123; <span class="comment">// existing mapping for key</span></div><div class="line">            V oldValue = e.value;</div><div class="line">            <span class="keyword">if</span> (!onlyIfAbsent || oldValue == <span class="keyword">null</span>)</div><div class="line">                e.value = value;</div><div class="line">            afterNodeAccess(e);</div><div class="line">            <span class="keyword">return</span> oldValue;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    ++modCount;</div><div class="line">    <span class="keyword">if</span> (++<span class="built_in">size</span> &gt; threshold)</div><div class="line">        resize();</div><div class="line">    afterNodeInsertion(evict);</div><div class="line">    <span class="keyword">return</span> <span class="keyword">null</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>另外再附上一张put方法完整流程图（点击可看大图）</p>
<p><img src="http://blog-img.itfuyun.com/hashmap.png" alt="图6（来源网络）"></p>
<h4 id="get-Object-key-方法"><a href="#get-Object-key-方法" class="headerlink" title="get(Object key)方法"></a>get(Object key)方法</h4><p>同样，从源码中可以看到主要是调用了getNode这个方法</p>
<figure class="highlight processing"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> V <span class="built_in">get</span>(<span class="keyword">Object</span> <span class="built_in">key</span>) &#123;</div><div class="line">    Node&lt;K,V&gt; e;</div><div class="line">    <span class="keyword">return</span> (e = getNode(hash(<span class="built_in">key</span>), <span class="built_in">key</span>)) == <span class="keyword">null</span> ? <span class="keyword">null</span> : e.value;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>下面贴上getNode的源码，里面也添加了相关注释<br><figure class="highlight gauss"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">final Node&lt;K,V&gt; getNode(int hash, Object <span class="built_in">key</span>) &#123;</div><div class="line">    Node&lt;K,V&gt;[] <span class="built_in">tab</span>; Node&lt;K,V&gt; first, e; int n; K k;</div><div class="line">    <span class="comment">//判断table是否为空并且长度不为0，根据hash得到应该存放的区域，区域头节点也不为空</span></div><div class="line">    <span class="keyword">if</span> ((<span class="built_in">tab</span> = table) != <span class="built_in">null</span> &amp;&amp; (n = <span class="built_in">tab</span>.length) &gt; <span class="number">0</span> &amp;&amp;</div><div class="line">        (first = <span class="built_in">tab</span>[(n - <span class="number">1</span>) &amp; hash]) != <span class="built_in">null</span>) &#123;</div><div class="line">        <span class="comment">//是否与头结点的key相同，相同则直接返回该节点</span></div><div class="line">        <span class="keyword">if</span> (first.hash == hash &amp;&amp; <span class="comment">// always check first node</span></div><div class="line">            ((k = first.<span class="built_in">key</span>) == <span class="built_in">key</span> || (<span class="built_in">key</span> != <span class="built_in">null</span> &amp;&amp; <span class="built_in">key</span>.equals(k))))</div><div class="line">            <span class="keyword">return</span> first;</div><div class="line">        <span class="comment">//头结点不匹配则进入遍历</span></div><div class="line">        <span class="keyword">if</span> ((e = first.next) != <span class="built_in">null</span>) &#123;</div><div class="line">            <span class="comment">//如果是树节点，遍历红黑树，找到节点立即返回该节点，具体红黑树的遍历查询需要查看getTreeNode方法</span></div><div class="line">            <span class="keyword">if</span> (first instanceof TreeNode)</div><div class="line">                <span class="keyword">return</span> ((TreeNode&lt;K,V&gt;)first).getTreeNode(hash, <span class="built_in">key</span>);</div><div class="line">            <span class="comment">//否则遍历链表，找到节点立即返回该节点</span></div><div class="line">            <span class="keyword">do</span> &#123;</div><div class="line">                <span class="keyword">if</span> (e.hash == hash &amp;&amp;</div><div class="line">                    ((k = e.<span class="built_in">key</span>) == <span class="built_in">key</span> || (<span class="built_in">key</span> != <span class="built_in">null</span> &amp;&amp; <span class="built_in">key</span>.equals(k))))</div><div class="line">                    <span class="keyword">return</span> e;</div><div class="line">            &#125; <span class="keyword">while</span> ((e = e.next) != <span class="built_in">null</span>);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="comment">//没有找到对应的key，说明不存在，返回null;</span></div><div class="line">    <span class="keyword">return</span> <span class="built_in">null</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>源码分析并不难，需要一颗平静的心，切勿浮躁。每个人的理解都不一样，选择自己的方式，效果会更明显。另外就是不能被一些专业的术语所吓到，很多所谓的术语其实很简单。</p>

        
        </div>
		
		
            
<div>
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div style="margin-bottom:10px">请作者喝杯咖啡吧！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
        <div id="wechat" style="display: inline-block">
          <a href="/css/images/wechatpay.png" class="fancybox fancybox.image" rel="group"><img id="wechat_qr" src="/css/images/wechatpay.png" alt="过眼浮云 WeChat Pay"></a>
          <p>微信打赏</p>
        </div>
        <div id="alipay" style="display: inline-block">
          <a href="/css/images/alipay.png" class="fancybox fancybox.image" rel="group"><img id="alipay_qr" src="/css/images/alipay.png" alt="过眼浮云 Alipay"></a>
          <p>支付宝打赏</p>
        </div>
    </div>
  </div>
</div>

        
		
		
            <! -- 添加版权信息 -->
<div class="article-footer-copyright">
<div>本站文章除注明转载外，均为本站原创或编译。欢迎任何形式的转载，但请务必注明出处。</div>
<div>转载请注明：文章转载自 IT浮云 <a href="/index.html" target="_blank" title="IT浮云">[http://www.itfuyun.com]</a></div>
<div>本文标题：HashMap 源码分析</div>
<div>本文地址：<a href="/posts/hashmap-source-code-analysis.html" target="_blank" title="HashMap 源码分析">http://www.itfuyun.com/posts/hashmap-source-code-analysis.html</a></div>
</div>
<! -- 添加版权信息 -->
        
		
        <footer class="article-footer">
            <div class="share-container">


    <div class="bdsharebuttonbox">
    <a href="#" class="bds_more" data-cmd="more">分享到：</a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
    <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
    <a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
</div>
<script>
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
</script>
<style>
    .bdshare_popup_box {
        border-radius: 4px;
        border: #e1e1e1 solid 1px;
    }
    .bdshare-button-style0-16 a,
    .bdshare-button-style0-16 .bds_more {
        padding-left: 20px;
        margin: 6px 10px 6px 0;
    }
    .bdshare_dialog_list a,
    .bdshare_popup_list a,
    .bdshare_popup_bottom a {
        font-family: 'Microsoft Yahei';
    }
    .bdshare_popup_top {
        display: none;
    }
    .bdshare_popup_bottom {
        height: auto;
        padding: 5px;
    }
</style>


</div>

            
    
        <a href="http://www.itfuyun.com/posts/hashmap-source-code-analysis.html#comments" id="sourceId::posts/hashmap-source-code-analysis.html" class="article-comment-link cy_cmt_count">评论</a>
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/posts/freemarker-generates-static-files.html" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    Freemarker生成静态文件
                
            </div>
        </a>
    
    
        <a href="/posts/java-cookie-utils.html" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">Java操作Cookie工具类</div>
        </a>
    
</nav>


    
</article>


    
    
        <section id="comments">
    <div id="SOHUCS" sid="posts/hashmap-source-code-analysis.html"></div>
</section>
    

</section>
            
                
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="no-thumbnail">
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/design-pattern/">设计模式</a></p>
                            <p class="item-title"><a href="/posts/design-pattern-lsp.html" class="title">设计模式之-里氏替换原则LSP</a></p>
                            <p class="item-date"><time datetime="2017-10-20T05:50:53.000Z" itemprop="datePublished">2017-10-20</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/programming/">编程</a></p>
                            <p class="item-title"><a href="/posts/freemarker-generates-static-files.html" class="title">Freemarker生成静态文件</a></p>
                            <p class="item-date"><time datetime="2017-10-16T07:58:51.000Z" itemprop="datePublished">2017-10-16</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/source-code-analysis/">源码分析</a></p>
                            <p class="item-title"><a href="/posts/hashmap-source-code-analysis.html" class="title">HashMap 源码分析</a></p>
                            <p class="item-date"><time datetime="2017-10-14T06:31:55.000Z" itemprop="datePublished">2017-10-14</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/programming/">编程</a></p>
                            <p class="item-title"><a href="/posts/java-cookie-utils.html" class="title">Java操作Cookie工具类</a></p>
                            <p class="item-date"><time datetime="2017-09-27T14:53:34.000Z" itemprop="datePublished">2017-09-27</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/programming/">编程</a></p>
                            <p class="item-title"><a href="/posts/rapid-generator.html" class="title">告别枯燥的CRUD，Java代码生成器的使用</a></p>
                            <p class="item-date"><time datetime="2017-09-26T12:49:39.000Z" itemprop="datePublished">2017-09-26</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/other/">其他</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/source-code-analysis/">源码分析</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/programming/">编程</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/design-pattern/">设计模式</a><span class="category-list-count">1</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">归档</h3>
        <div class="widget">
            <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">3</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/tags/cookie/" style="font-size: 10px;">-cookie</a> <a href="/tags/hexo/" style="font-size: 10px;">-hexo</a> <a href="/tags/代码生成/" style="font-size: 10px;">-代码生成</a> <a href="/tags/HashMap/" style="font-size: 10px;">HashMap</a> <a href="/tags/freemarker/" style="font-size: 10px;">freemarker</a> <a href="/tags/lsp/" style="font-size: 10px;">lsp</a> <a href="/tags/里氏替换/" style="font-size: 10px;">里氏替换</a>
        </div>
    </div>

    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

            
        </div>
        <footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            &copy; 2018 IT浮云<br>
            Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>. Theme by <a href="http://github.com/ppoffice">PPOffice</a>
        </div>
    </div>
</footer>
        
    
    <script id="cy_cmt_num" src="https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=cytezlr4l"></script>
    <script charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/changyan.js" ></script>
    <script type="text/javascript">
    window.changyan.api.config({
    appid: 'cytezlr4l',
    conf: '7625b051042273ad10802550abd3d130'
    });
    </script>




    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>